﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KLY.DataModels;
using KLY.ServiceCore;
using PagedList;

namespace KLY_Webs.Controllers.ApiControl
{
    public class FreightController : Controller
    {
        //
        // GET: /Freight/
        public ActionResult Vipline(SearchLineRequest request, int? page)
        {
            SearchLineResponse response;
            ViewBag.Start_Area = request.start_area;
            ViewBag.End_Area = request.end_area;

            if (request != null && !string.IsNullOrWhiteSpace(request.start_area) && !string.IsNullOrWhiteSpace(request.end_area))
            {
                var processer = new SearchViplineInfo(request);
                response = processer.Process();
                int pageNumber = (page ?? 1);
                int pageSize = BizCommon.PagedListPageSize;
                if (response != null && response.Result != null && response.Result.pub_list != null && response.Result.pub_list.Any())
                {
                    return View(response.Result.pub_list.ToPagedList(pageNumber, pageSize));
                }
            }
            response = new SearchLineResponse
            {
                Result = new SearchLineResult
                {
                    pub_list = new SearchLine[] 
                    { 

                    }
                }
            };
            return View(response.Result.pub_list.ToPagedList(1, 1));
        }

        public ActionResult Zhengche(SearchTruckRequest request, int? page)
        {
            SearchTruckResponse response;
            ViewBag.Start_Area = request.start_area;
            ViewBag.End_Area = request.end_area;
            ViewBag.Vehicle_Type = request.vehicle_type;
            ViewBag.Vehicle_Len = request.vehicle_len;
            ViewBag.Vehicle_Load = request.vehicle_load;
            ViewBag.Time_End = request.time_end;

            if (request != null && !string.IsNullOrWhiteSpace(request.start_area) && !string.IsNullOrWhiteSpace(request.end_area))
            {
                var processer = new SearchTruckInfo(request);
                response = processer.Process();
                int pageNumber = (page ?? 1);
                int pageSize = BizCommon.PagedListPageSize;
                if (response != null && response.result != null && response.result.pub_list != null && response.result.pub_list.Any())
                {
                    return View(response.result.pub_list.ToPagedList(pageNumber, pageSize));
                }
            }
            response = new SearchTruckResponse
            {
                result = new SearchResult
                {
                    pub_list =new SearchTruckVehiclePub[]
                    {

                    }
                }
            };
            return View(response.result.pub_list.ToPagedList(1, 1));
        }

        //[HttpPost]
        //public ActionResult Zhengche(SearchTruckRequest request,int? page)
        //{
        //    var processer = new  SearchTruckInfo(request);
        //    var response = processer.Process();
        //    int pageNumber = (page ?? 1);
        //    int pageSize = response.result.Total_Count / 2;

        //    return View(response.result.pub_list.ToPagedList(pageNumber, pageSize));
        //}
	}
}